<?php
namespace app\admin\controller;

use app\admin\model\Activity;
use app\admin\model\Comment;
use app\admin\model\Config;
use app\admin\model\Course;
use app\admin\model\Focus;
use app\admin\model\Log;
use app\admin\model\NewsCommunication;
use app\admin\model\NewsIssued;
use app\admin\model\NewsLetter;
use app\admin\model\ResourceFile;
use app\admin\model\WechatLog;
use app\admin\model\WechatUser;
use app\home\model\Browse;
use app\home\model\Collect;
use app\home\model\Construction;
use app\home\model\Like;
use app\user\model\UcenterMember;
use think\Controller;
use think\Db;

class Index extends Admin {

    public function index() {
        $map['status'] = ['egt',0];
        // 通讯录总人数
        $userCount = WechatUser::where(['status' => 1])->count();
        $this->assign('userCount',$userCount);
        $userTotal = WechatUser::where($map)->count();
        $this->assign('userTotal', $userTotal);
        // 评论数
        $commentTotal = \app\home\model\Comment::where($map)->count();
        $this->assign('commentTotal', $commentTotal);
        // 点赞数
        $likeTotal = Like::where($map)->count();
        $this->assign('likeTotal', $likeTotal);
        // 收藏数
        $collectTotal = Collect::where($map)->count();
        $this->assign('collectTotal', $collectTotal);
        //浏览总数
        $browseTotal = Browse::where($map)->count();
        $this->assign('browseTotal',$browseTotal);
        //党群建设动态
        $construction = Construction::where($map)->count();
        $this->assign('constructionTotal',$construction);
        //文章发布总数
        $Communication = \app\home\model\NewsCommunication::where($map)->count();
        $Issued = NewsIssued::where($map)->count();
        $Letter = NewsLetter::where($map)->count();
        $sum = array($Communication,$Issued,$Letter);
        $publishTotal = array_sum($sum);
        $this->assign('publishTotal',$publishTotal);
        //文件上传总数
        $fileTotal = ResourceFile::where($map)->count();
        $this->assign('fileTotal',$fileTotal);

        $mysqlinfo = Db::query("select version()");
        //配置信息
        $server_config = array(
            'os' => $_SERVER["SERVER_SOFTWARE"], //获取服务器标识的字串
            'version' => PHP_VERSION, //获取PHP服务器版本
            'time' => date("Y-m-d H:i:s", time()), //获取服务器时间
            'pc' => $_SERVER['SERVER_NAME'], //当前主机名
            'osname' => php_uname(), //获取系统类型及版本号
            'language' => $_SERVER['HTTP_ACCEPT_LANGUAGE'], //获取服务器语言
            'port' => $_SERVER['SERVER_PORT'], //获取服务器Web端口
            'max_upload' => ini_get("file_uploads") ? ini_get("upload_max_filesize") : "Disabled", //最大上传
            'max_ex_time' => ini_get("max_execution_time")."秒", //脚本最大执行时间
            'mysql_version' => $mysqlinfo[0]['version()'],
        );
        $this->assign('server_config',$server_config);
        return $this->fetch();
    }

    public function search() {
        return $this->fetch();
    }

    /**
     * 修改密码
     */
    public function editpassword(){
        if(IS_POST){
            $id = input('id');
            $password = input('password');
            $repassword = input('repassword');
            if(!empty($password)){
                if($password != $repassword){
                    return $this->error('两次输入的密码不一致!');
                }else{
                    $data['password'] = think_ucenter_md5($repassword, config('uc_auth_key')); //转码存入数据库
                }
            }else{
                return $this->error("密码不能为空!");
            }
            $result = UcenterMember::where('id',$id)->update($data);
            if($result){
                return $this->success("修改成功",Url('Index/index'));
            }else{
                return $this->error("修改失败");
            }
        }else{
            //获取用户的信息
            $user = session('user_auth');
            $this->assign('user',$user);
            
            return $this->fetch();
        }
    }
}